package pe

import (
	"risc-vm/common"
)

const MAGIC uint32 = 0x7f454c46

type ELF struct {
	// e_ident (16 bytes, ELF identification string)
	Magic uint32
	// 1 -> 32 bit, 2 -> 64 bit
	EI_Class uint8
	// 1、小端模式(little) 2、大端模式(big)
	EI_Data uint8
	// currently always 1
	EI_Version uint8
	// marks beginning of padding
	EI_Pad uint8
	// 这8个字节看起来没啥意义，先放着
	Other1 uint64
	// type of object file. should be 2 for executable
	E_Type uint16
	// architecture
	E_Machine uint16
	// elf version (should always be 1)
	E_Version uint32
	// virtual address of entry point into program (0x10000)
	E_Entry *common.Long
	// offset for program header
	E_Phoff *common.Long
	// offset for section header
	E_Shoff *common.Long
	// processor flags
	E_Flags uint32
	// elf header size
	E_Ehsize uint16
	// size of each individual entry in program header table
	E_Phentsize uint16
	// number of entries in program header table
	E_Phnum uint16
	// size of each individual entry in section header table
	E_Shentsize uint16
	// number of entries in section header table
	E_Shnum uint16
	// section header string table index
	E_Shstrndx uint16
}

type SectionHeader struct {
	Name  uint32
	Type  uint32
	Flags *common.Long
	Addr  *common.Long
	Offs  *common.Long
	Size  *common.Long
}

type PE struct {
	ELF            ELF
	SectionHeaders []SectionHeader
}

func New() *PE {
	return new(PE).Init()
}

func (pe *PE) Init() *PE {
	return pe
}
